package com.example.ams.repository;

import com.example.ams.entity.OvertimeRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 加班记录数据访问层
 * Overtime Record Repository
 */
@Repository
public interface OvertimeRecordRepository extends JpaRepository<OvertimeRecord, Long> {

    /**
     * 根据员工ID查询加班记录
     */
    List<OvertimeRecord> findByEmployeeIdOrderByStartTimeDesc(Long employeeId);

    /**
     * 根据员工ID和时间范围查询
     */
    @Query("SELECT o FROM OvertimeRecord o WHERE o.employeeId = :employeeId " +
           "AND o.startTime >= :startTime AND o.startTime <= :endTime " +
           "ORDER BY o.startTime DESC")
    List<OvertimeRecord> findByEmployeeIdAndTimeRange(
            @Param("employeeId") Long employeeId,
            @Param("startTime") Date startTime,
            @Param("endTime") Date endTime);

    /**
     * 根据时间范围查询所有记录
     */
    @Query("SELECT o FROM OvertimeRecord o WHERE o.startTime >= :startTime " +
           "AND o.startTime <= :endTime ORDER BY o.startTime DESC")
    List<OvertimeRecord> findByTimeRange(
            @Param("startTime") Date startTime,
            @Param("endTime") Date endTime);

    /**
     * 根据状态查询
     */
    List<OvertimeRecord> findByStatusOrderByStartTimeDesc(OvertimeRecord.Status status);
}

